import 'package:flutter/material.dart';
import '../experiment/experiment.dart';
import '../important_news/important_news.dart';
import '../my/my.dart';
import '../news/news.dart';
import '../political_Theory/political_Theory.dart';

class Nav extends StatefulWidget {
  Nav({Key key}) : super(key: key);

  _NavState createState() => _NavState();
}

class _NavState extends State<Nav> {
  int _currentIndex = 2;
  List mainPage = [
    News(),
    ImportantNews(),
    PoliticalTheory(),
    Experiment(),
    My()
  ];
  void _changCurrentIndex(int value) {
    setState(() {
      this._currentIndex = value;
    });
  }

  // Widget _siZhengHong(){
  //      if(this._currentIndex == 2){
  //        return Image.asset('images/思政红.jpg');
  //      }
  //      return Image.asset('images/思政2.jpg');
  // }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
          children: [
            Offstage(
              offstage: _currentIndex != 0,
              child: mainPage[0],
            ),
            Offstage(
              offstage: _currentIndex != 1,
              child: mainPage[1],
            ),
            Offstage(
              offstage: _currentIndex != 2,
              child: mainPage[2],
            ),
            Offstage(
              offstage: _currentIndex != 3,
              child: mainPage[3],
            ),
            Offstage(
              offstage: _currentIndex != 4,
              child: mainPage[4],
            ),
          ],
        ),
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.chat), title: Text('消息')),
          BottomNavigationBarItem(icon: Icon(Icons.stars), title: Text('要闻')),
          BottomNavigationBarItem(icon: Icon(Icons.camera), title: Text('思政')),
          BottomNavigationBarItem(icon: Icon(Icons.flag), title: Text('实践')),
          BottomNavigationBarItem(icon: Icon(Icons.person), title: Text('我的')),
        ],
        currentIndex: _currentIndex,
        fixedColor: Colors.red,
        onTap: _changCurrentIndex,
      ),
      floatingActionButton: Container(
        padding: EdgeInsets.fromLTRB(0, 56, 0, 0),
        child: FloatingActionButton(
          elevation: 0.0,
          child: this._currentIndex==2?Image.asset('images/sizheng_red.jpg'):Image.asset('images/sizheng.jpg'),
          onPressed: () {
            setState(() {
             this._currentIndex = 2; 
            });
          },
          backgroundColor: Color.fromRGBO(250, 250, 250, 1),
        ),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
    );
  }
}
